package com.company.zonghelizi.rili;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

/*
    日历复习题，日历时间类
 */
public class RiLi {
    public static void main(String[] args) throws ParseException {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入日期,打印相应的日历(格式为2020-01-01)");
        String input = sc.nextLine();
        SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        Date date = s.parse(input);
        c.setTime(date);
        int jinday = c.get(Calendar.DATE);
        c.set(Calendar.DATE,1);
        // 一个月最多的一天
        int day = c.getActualMaximum(Calendar.DATE);
        int week = c.get(Calendar.DAY_OF_WEEK);
        System.out.println("日\t一\t二\t三\t四\t五\t六");
        for(int j=0;j<week-1;j++){
            System.out.print("\t");
        }
        for (int i = 1; i <= day; i++) {
            if(i==jinday){
                System.out.print("*");
            }
            System.out.print(i+"\t");
//            if((i+week-1)%7==0){
//                System.out.println();
//            }
            c.set(Calendar.DATE,i);
            if(c.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY){
                System.out.println();
            }
        }
    }
}

/*
学生张三向李四借入了10块钱
 */
class Studens{
    public int money = 100;
    public String name;

    public Studens(String name) {
        this.name = name;
    }

    public void jieru(Studens stu,int money){
        stu.jiechu(this,money);
        System.out.println("学生"+this.name+"借了学生"+stu.name+money+"元钱");
    }

    public void jiechu(Studens stu,int money){
        this.money -= money;
        stu.money += money;
    }


}
class Test{
    public static void main(String[] args) {
        Studens studens1 = new Studens("张三");
        Studens studens2 = new Studens("李四");
        studens1.jieru(studens2,10);

    }
}

/**
 * 用户张三向用户李四用支付宝转账100
 */
class Company{
    private String name;
    private Account[] accounts = new Account[5];
    public Company(String name){
        this.name = name;
        this.accounts[0] = new Account("10001","1111",5000);
        this.accounts[1] = new Account("10002","1111",6000);
        this.accounts[2] = new Account("10003","1111",7000);
        this.accounts[3] = new Account("10004","1111",4000);
        this.accounts[4] = new Account("10005","1111",3000);
    }
    public int zhuan(String fromId,String password,String toId,int money){
        // 登录
        // 账户id是否存在
        Account from = findAccount(fromId);  // 判断自己账户是否存在
        if(null == from){
            return Code.ID_ERROR;
        }
        // 判断密码
        if(!from.getPasssword().equals(password)){
            return Code.PASSWORD_ERROR;
        }
        Account to = findAccount(toId);   // 判断对方账户是否存在
        if(null == to){
            return Code.TO_ID_ERROR;
        }
        // 判断余额
        if(money>from.getMoney()){
            return Code.MONEY_ERROR;
        }
        // 转账
        from.setMoney(from.getMoney()-money);
        to.setMoney(to.getMoney()+money);
        return Code.SUCCESS;
    }

    private Account findAccount(String id){
        for (int i = 0; i < this.accounts.length; i++) {
            if(id.equals(this.accounts[i].getId())){
                return  this.accounts[i];
            }
        }
        return null;
    }

}
interface Code{
    int SUCCESS = 0;
    int ID_ERROR = 1;
    int PASSWORD_ERROR = 2;
    int TO_ID_ERROR = 3;
    int MONEY_ERROR = 4;
}
class Account{
    private String id;
    private String passsword;
    private int money;

    public Account(String id, String passsword, int money) {
        this.id = id;
        this.passsword = passsword;
        this.money = money;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getPasssword() {
        return passsword;
    }

    public void setPasssword(String passsword) {
        this.passsword = passsword;
    }

    public int getMoney() {
        return money;
    }

    public void setMoney(int money) {
        this.money = money;
    }

    @Override
    public String toString() {
        return "Account{" +
                "id='" + id + '\'' +
                ", passsword='" + passsword + '\'' +
                ", money=" + money +
                '}';
    }
}
class User{
    private String name;

    public User(String name) {
        this.name = name;
    }

    public void askforzhuan(String id,String password ,String toid,int money,Company company){
        int result = company.zhuan(id,password,toid,money);
        switch(result){
            case Code.SUCCESS:
                System.out.println("成功");
                break;
            case Code.ID_ERROR:
                System.out.println("账户ID不正确");
                break;
            case Code.PASSWORD_ERROR:
                System.out.println("密码不正确");
                break;
            case Code.TO_ID_ERROR:
                System.out.println("对方账户不存在");
                break;
            case Code.MONEY_ERROR:
                System.out.println("余额不足");
                break;
            default:
                System.out.println("系统异常");
        }
    }
}
class Tests{
    public static void main(String[] args) {
        User user = new User("zz");
        Company alipy = new Company("支付宝");
        user.askforzhuan("10001","111","10002",500,alipy);
    }
}
